package com.qianf.qfoffice.service.impl;

import com.github.pagehelper.PageHelper;
import com.qianf.qfoffice.dao.ExercisesDao;
import com.qianf.qfoffice.entity.Exercises;
import com.qianf.qfoffice.service.ExercisesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExercisesServiceImpl implements ExercisesService {

    @Autowired
    private ExercisesDao exercisesDao;

    @Override
    public boolean addExercises(Exercises exercises) {

        int i = exercisesDao.addExercises(exercises);

        if(i>0){
            return true;
        }
        else {
            return false;
        }
    }

    /**
     * 分页展示习题
     * @param page
     * @param limit
     * @return
     */
    @Override
    public List<Exercises> selectExercises(Integer page,Integer limit) {

        PageHelper.startPage(page,limit);
        List<Exercises> exercises = exercisesDao.selectExercises();

        return exercises;
    }

    /**
     * 根据id删除练习题
     * @param id
     * @return
     */
    @Override
    public boolean deleteExerciseById(int id) {
        int num = exercisesDao.deleteExerciseById(id);
        if(num>0){
            return true;
        }else {
            return false;
        }
    }

    /**
     * 根据id查询习题信息
     * @param id
     * @return
     */
    public Exercises selectExerciseById(int id){

        Exercises exercises = exercisesDao.selectExerciseById(id);

        return exercises;
    }

}
